package com.dongdongshop.controller;
import com.dongdongshop.data.PageResult;
import com.dongdongshop.data.Result;
import com.dongdongshop.domain.rep.BrandReq;
import com.dongdongshop.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RefreshScope
@RequestMapping("brand")
@Api(tags = "东东商城品牌管理")
public class BrandController {

    @Autowired
    private BrandService brandService;


    /**
     * 品牌分页查询
     * @param brandReq
     * @return
     */
    @ApiOperation("品牌分页查询")
    @PostMapping("queryPage")
    public Result<PageResult> queryPage(@RequestBody BrandReq brandReq){
        PageResult pageResult=brandService.queryPage(brandReq);
        return Result.success(pageResult);
    }


    /**
     * 增加修改操作
     * @param brandReq
     * @return
     */
    @PutMapping("save")
    @ApiOperation("品牌增加修改操作")
    public Result save(@RequestBody BrandReq brandReq){
        brandService.save(brandReq);
        return Result.success();
    }

    /**
     * 品牌删除操作
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    @ApiOperation("品牌删除操作")
    public Result delete(@PathVariable("id") Long id){
        brandService.delete(id);
        return Result.success();
    }



    /**
     * 品牌批量删除操作
     * @param ids
     * @return
     */
    @PatchMapping("batchRemove")
    @ApiOperation("品牌批量删除操作")
    public Result batchRemove(@RequestBody List<Integer> ids){
        brandService.batchRemove(ids);
        return Result.success();
    }
}
